home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Storage / Bento / CM / Containr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  14.2 KB  |  302 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:         Containr.h 
  3.  
  4.     Contains:    Container Manager Containers Interfaces
  5.  
  6.     Written by:    Ira L. Ruben
  7.  
  8.     Owned by:    Ed Lai
  9.  
  10.     Copyright:    © 1991 - 1996 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <4>     8/22/96    EL        1376276: add alwaysToTmpFree field to
  15.                                     Container.
  16.          <3>     8/13/96    DM        1362809: field to record disabled
  17.                                                     containers on error
  18.          <2>     1/15/96    TJ        Cleaned Up
  19.          <3>     9/30/94    EL        #1182275 rename mergeCandidate to
  20.                                                     updateMergeCandidate.
  21.          <2>     8/26/94    EL        #1182275 Add new field mergeCandidate to
  22.                                                     the container struct.
  23.          <4>      5/5/94    EL        Minor version one for new data format not
  24.                                                     supported in 2.0.
  25.          <3>     3/31/94    EL        Add field mergeInSize to container.
  26.                                                     #1150214
  27.          <2>     3/17/94    EL        Add support in container data structure for
  28.                                                     delete garbage and truncate back to
  29.                                                     original size.
  30.          <1>      2/3/94    EL        first checked in
  31.          <2>     1/19/94    EL        Add tmpFreeList to container.
  32.  
  33.     To Do:
  34. */
  35.  
  36. /*---------------------------------------------------------------------------*
  37.  |                                                                           |
  38.  |                            <<<  Containr.h  >>>                           |
  39.  |                                                                           |
  40.  |                  Container Manager Containers Interfaces                  |
  41.  |                                                                           |
  42.  |                               Ira L. Ruben                                |
  43.  |                                 12/02/91                                  |
  44.  |                                                                           |
  45.  |                  Copyright Apple Computer, Inc. 1991-1994                 |
  46.  |                           All rights reserved.                            |
  47.  |                                                                           |
  48.  *---------------------------------------------------------------------------*
  49.  
  50.  This header defines the container control block and some common info about the container
  51.  label.  Everyone includes this thing since it acts as the "global variable" data space
  52.  tied to each individual opened or embedded container.
  53. */
  54.  
  55. #ifndef __CONTAINEROPS__
  56. #define __CONTAINEROPS__
  57.  
  58. #include <setjmp.h>
  59.  
  60. /*------------------------------------------------------------------------------------*
  61.  | W A R N I N G - - -> this header as well as  TOCObjs.h   and  TOCEnts.h   all have |
  62.  |                      mutual references.  The include order is NOT arbitrary.  It's |
  63.  |                      the only one that works!  Even with it we have to do some     |
  64.  |                      forward struct pointer references of the form "struct foo *p" |
  65.  *------------------------------------------------------------------------------------*/
  66.  
  67. #ifndef __CMTYPES__
  68. #include "CMTypes.h"
  69. #endif
  70. #ifndef __CM_API_TYPES__
  71. #include "CMAPITyp.h"
  72. #endif
  73. #ifndef __LISTMGR__
  74. #include "ListMgr.h"
  75. #endif
  76. #ifndef __HANDLERS__
  77. #include "Handlers.h"
  78. #endif
  79. #ifndef __SESSIONDATA__
  80. #include "Session.h"          
  81. #endif
  82. #ifndef __TOCENTRIES__
  83. #include "TOCEnts.h"   
  84. #endif
  85. #ifndef __TOCOBJECTS__
  86. #include "TOCObjs.h"   
  87. #endif
  88.  
  89.                                    CM_CFUNCTIONS
  90.  
  91. struct SessionGlobalData;
  92. struct Container;
  93. struct TOCObject;
  94. struct TOCValueHdr;
  95. struct TOCValue;
  96. struct EmbeddedContainer;
  97. struct GlobalName;
  98.  
  99.  
  100. #define MagicByteSequence "\xA4""CM""\xA5""Hdr""\xD7"        /* Must be 8 characters                    */
  101.  
  102. #define MajorVersion            2                                                            /* major format version number    */
  103. #define MinMinorVersion        0                                                            /* min minor format version       */
  104. #define MinorVersion            1                                                            /* minor format version number    */
  105.  
  106. #define MinStdObjectID        CM_StdObjID_MinGeneralID            /* min standard object id                */
  107. #define MinUserObjectID        0x00010000UL                                    /* min user object id                        */
  108.  
  109. #define IsStdObject(id)        (((id) & 0xFFFF0000UL) == 0)     /* tests for ID type                        */
  110. #define IsUserObject(id)     (((id) & 0xFFFF0000UL) != 0)
  111.  
  112. /* the default and the minimum acceptable generation number is 1                                                */            
  113. #define kCMDefaultGeneration    1                                                    /* the default generation             */
  114.  
  115. /* The following is used to test for updating modes that use one container to update         */
  116. /* another...                                                                                                                                                        */
  117.  
  118. #define UPDATING(updatingContainer) (((updatingContainer)->useFlags & (kCMUpdateTarget | kCMUpdateByAppend)) != 0)
  119.  
  120. /* The following macro is used to see if touched records are to be generated...                    */
  121.  
  122. #define TouchIt(updatingContainer, container) (updatingContainer->touchTheValue     && \
  123.                                                                                              (updatingContainer) != (container) && \
  124.                                                                                              UPDATING(updatingContainer))
  125.  
  126.  
  127.                                                 /*-------------------------------*
  128.                                                  | The "Container Control Block" |
  129.                                                  *-------------------------------*/
  130.  
  131. struct Container {                                                /* Layout for a "Container Control Block":        */
  132.     ListLinks                        containerLinks;            /*    in-use Containers links (must be first)    */
  133.     struct Container        *thisContainer;            /*         validation check on the container ptr        */
  134.     
  135.     struct SessionGlobalData *sessionData;    /*         pointer of session (task) global data        */
  136.     
  137.     struct Container        *updatingContainer;    /*        ptr to container recording new updates    */
  138.     CM_USHORT                        depth;                            /*        target container "depth"                                */
  139.     CMBoolean                        openingTarget;            /*        true ==> updater is opening target            */
  140.     CMBoolean                        updateMergeCandidate;    /*        true ==> container may be merged            */
  141.     
  142.     struct Container        *targetContainer;        /*        ptr to container being updated or used    */
  143.     CMValue                            pointingValue;            /*        refNum of container's pointing value        */
  144.     
  145.     HandlerOps                     handler;                        /*         handler basic operations vector                    */
  146.     MetaHandlerPtr             metaHandlerProc;        /*        ptr to type and "metahandler" proc            */
  147.     CMRefCon                          refCon;                            /*         handler's refCon                                                */
  148.     
  149.     unsigned char                magicBytes[10];            /*        magic byte sequence                                            */
  150.     CM_USHORT                        majorVersion;                /*         major format version                                        */
  151.     CM_USHORT                        minorVersion;                /*        minor format version                                        */
  152.     
  153.     CM_USHORT                         containerFlags;            /*        container ("label") flags                                */
  154.     CM_ULONG                        generation;                    /*        generation number                                                */
  155.     CM_ULONG                        tocBufSize;                    /*        actual TOC buffer size (lbl value*1024)    */
  156.     
  157.     void                                 *toc;                                /*        ptr to TOC (this container's or target)    */
  158.     void                                 *privateTOC;                /*        ptr to this container's private TOC            */
  159.     CM_ULONG                        tocOffset;                    /*        offset to the start of the TOC                    */
  160.     CM_ULONG                        tocSize;                        /*        total size of the TOC in the container    */
  161.     CMBoolean                        tocFullyReadIn;            /*        true ==> an "old" TOC is fully loaded        */
  162.     CMBoolean                        usingTargetTOC;            /*        true ==> currently using target's TOC        */
  163.     CM_ULONG                        tocInputOffset;            /*        current TOC input offset                                */
  164.     void                                *ioBuffer;                    /*        current buffered TOC I/O buffer                    */
  165.     void                                *tocIOCtl;                    /*        current TOC I/O control block pointer        */
  166.     
  167.     struct TOCValue            *tocIDSeedValue;        /*        ptr to TOC ID seed value       (not hdr)*/
  168.     struct TOCValue            *tocIDMinSeedValue;    /*        ptr to TOC ID min seed value   (not hdr)*/
  169.     struct TOCValue            *tocObjValue;                /*        ptr to TOC object value        (not hdr)*/
  170.     struct TOCValue            *tocContainerValue;    /*        ptr to TOC container value     (not hdr)*/
  171.     struct TOCValue         *spaceDeletedValue;    /*        ptr to TOC space deleted value (not hdr)*/
  172.     struct TOCValue         *tocNewValuesValue;    /*        ptr to TOC new values TOC             (not hdr)*/
  173.     struct TOCValueHdr    *freeSpaceValueHdr;    /*        ptr to TOC free list (this IS value hdr)*/
  174.     struct TOCValueHdr    *deletesValueHdr;        /*        ptr to TOC deletes list (also value hdr)*/
  175.     ListHdr                            tmpList;                        /*        free space available at close time            */
  176.         
  177.     void                                *globalNameTable;        /*         ptr to global name tbl (or target)            */
  178.     void                                *privateGlobals;        /*         ptr to this container's global name tbl    */
  179.     CMBoolean                        usingTargetGlobals;    /*        true ==> currently using target's glbls    */
  180.     CMBoolean                        deleteGarbage;            /*        garbage collect before closing                    */
  181.  
  182.     CM_ULONG                        nextStdObjectID;        /*        next available std object id number            */
  183.     CM_ULONG                        nextUserObjectID;        /*        next available user object id number        */
  184.     
  185.     CM_USHORT                        useFlags;                        /*        container use flags                                            */
  186.     CM_ULONG                        physicalEOF;                /*        next free byte in the container                    */
  187.     CM_ULONG                        logicalEOF;                    /*        offset to highest byte written + 1            */
  188.     CM_ULONG                        maxValueOffset;            /*        max+1 allowed for value definitions            */
  189.     CM_ULONG                        originalEOF;                /*        size before update begins                                */
  190.  
  191.     CM_ULONG                        mergeInSize;                /*        the size of previous container merged in*/
  192.         
  193.     ListHdr                         deletedValues;             /*         list of all deleted values (headers)        */
  194.     
  195.     ListHdr                         embeddedContainers; /*         list of containers embedded in this one    */
  196.     struct TOCValueHdr    *embeddedValue;            /*        ptr to valueHdr for embedded container    */
  197.     struct EmbeddedContainer *parentListEntry;/*    back ptr to parent's list entry                    */
  198.     
  199.     void                                 *tocActions;                /*        ptr to TOC walk through (private) data    */
  200.     
  201.     CM_SHORT                        getBaseValueOk;            /*        >0 ==> CMGetBaseValue() allowed                    */
  202.     struct TOCValueHdr    *dynamicBaseValueHdr;/*        CMReleaseValue() dynamic value base            */
  203.     CM_LONG                            nbrOfDynValues;            /*        count of dynamic values in container        */
  204.     
  205.     CMProperty                    dynValueProperty;        /*        property refNum for dynamic values            */
  206.     CMProperty                    baseTypesProperty;    /*        property refNum for base types                    */
  207.     
  208.     CMBoolean                        trackFreeSpace;            /*        true ==> allows tracking of freed space    */
  209.     CMBoolean                        touchTheValue;            /*        true ==> appropriately record the touch    */
  210.     
  211.     CMBoolean                        alwaysToTmpFree;        /*        true ==> delete data to tmp free only        */
  212.  
  213.     ListHdr                         activeIOBuffers;        /*         list of active buffered I/O users                */
  214.     
  215.     struct TOCObject        *touchedChain;            /*         chain of objects touched during updating*/
  216.  
  217.     CM_LONG             fDisabled;          /* 0xDEAD if disabled, else 0x0 */
  218. };
  219. typedef struct Container Container, *ContainerPtr;
  220.  
  221. void CM_FIXEDARGS Container_Disable(ContainerPtr container);
  222.  
  223. // Let's not have the disable do anything until we are really ready:
  224. // define Container_Disable(container)
  225.  
  226. // define Container_Disable(container) (((ContainerPtr) container)->fDisabled = 0xDEAD)
  227.  
  228. /* NOTE: there is a mutual reference here between Container and TOCObject.  They refer    */
  229. /* to each other!  Thus we must do the weird "struct TOCObject" to define the list            */
  230. /* pointers above.  Sorry about that!                                                                                                        */
  231.  
  232. /* To make it easier and more self-documentating for using the "seeds" the following         */
  233. /* macros are provided.  These both assume the current container pointer is the variable*/
  234. /* "container".                                                                                                                                                    */
  235.  
  236. #define Seed        (container->tocIDSeedValue->value.imm.ulongValue)
  237. #define MinSeed (container->tocIDMinSeedValue->value.imm.ulongValue)
  238.  
  239. /* Similarly, we define the following macros to get at the updating TOC limits of non-    */
  240. /* private objects...                                                                                                                                        */
  241.  
  242. #define TOCNewValuesTOCOffset    (container->tocNewValuesValue->value.notImm.value)
  243. #define TOCNewValuesTOCSize        (container->tocNewValuesValue->value.notImm.valueLen)
  244.  
  245. /* The following defines the layout for list entries of a list of containers directly        */
  246. /* embedded in another container.  A container sort of is like a "super class" with its    */
  247. /* embedded containers being "subclasses".  There can be any number of embedded                 */
  248. /* containers open simultaneously (memory permitting). Each of these, in turn, can have    */
  249. /* embedded containers of their own!                                                                                                        */
  250.  
  251. struct EmbeddedContainer {                                /* Layout of a embedded container list entry:    */
  252.     ListLinks                      siblingsLinks;                /*    sibling Container links (must be first)    */
  253.     ContainerPtr             container;                        /*        ptr to the embedded container                        */
  254. };                                                                                /*        note, theValueHdr gives us father contnr*/
  255. typedef struct EmbeddedContainer EmbeddedContainer, *EmbeddedContainerPtr;
  256.  
  257.  
  258. /* Whenever we write to the container, we keep track of what we think is the EOF (last     */
  259. /* written byte + 1). We refer to this as the "logical EOF" since it may or may not be     */
  260. /* equal to the true container EOF.  For normal writing it probably is always the same.    */
  261. /* But for reusing free space we could be reusing free list space and the logical EOF     */
  262. /* may end up less than the physical EOF.                                                                                                */
  263.  
  264. /* This is portable code and we must assume         */
  265. /* that, at a minimum, the I/O handlers are using stream I/O.  We thus must take into     */
  266. /* account the possible extra space that could result from space reuse when the updates */
  267. /* use less space than what was originally there.                                                                                */
  268.  
  269. #define SetLogicalEOF(eof)    if ((eof) > container->logicalEOF) \
  270.                                                             container->logicalEOF = (eof)
  271.  
  272.  
  273.                                                 /*---------------------------------------*
  274.                                                  | Defined Layout of the Container Label |
  275.                                                  *---------------------------------------*
  276.  
  277. As defined by the API documentation, a container label is always placed at the END of the
  278. container and has the following layout:
  279.  
  280.              0                       8     10    12    14    16          20          24
  281.             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  282.             |      Magic Bytes      |flags|bufsz|major|minor|TOC offset |  TOC size |
  283.             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  284.                                     8              2     2     2     2        4           4
  285.  
  286. These are defined as "hard-coded" constants since the format is, by definition, platform
  287. independent.     The actual formatting and I/O for the container label is done by a handler
  288. because of this.                                                                                                                                                */
  289.  
  290. #define LBLmagicBytes            0                                /* 8 bytes: the magic byte identifier                    */
  291. #define LBLflags                    8                                /* 2                the label flags                                        */
  292. #define LBLbufSize             10                                /* 2                TOC buffer size / 1024                        */
  293. #define LBLmajorVersion     12                                /* 2                major format version number                */
  294. #define LBLminorVersion     14                                /* 2                minor format version number                */
  295. #define LBLtocOffset         16                                /* 4                offset to start of TOC                        */
  296. #define LBLtocSize             20                                /* 4                total byte size of the TOC                */
  297.  
  298. #define LBLsize                     24                                /* defined size of the container label                */
  299.  
  300.                                                          CM_END_CFUNCTIONS
  301. #endif
  302.